package projectEuler.net;

import junit.framework.TestCase;

public class Problem_003Test extends TestCase {
	public static void main(String args[]){
		junit.swingui.TestRunner.main(new String[]{"Test Problem 003"});
	}
	public Problem_003Test(String name){
		super(name);
	}
	public void testTwo() throws Exception{
		int[]lstP = Problem_003.factorPrimes(2);
		assertEquals(1, lstP.length);
		assertEquals(2, lstP[0]);
	}
	public void testThree() throws Exception{
		int[]lstP = Problem_003.factorPrimes(3);
		assertEquals(1, lstP.length);
		assertEquals(3, lstP[0]);
	}
	public void testFour() throws Exception{
		int[]lstP = Problem_003.factorPrimes(4);
		assertEquals(2, lstP.length);
		assertEquals(2, lstP[0]);
		assertEquals(2, lstP[1]);
	}
	public void testFive() throws Exception{
		int[] lstP=Problem_003.factorPrimes(5);
		assertEquals(1, lstP.length);
		assertEquals(5, lstP[0]);
	}
	public void testSix() throws Exception{
		int[] lstP = Problem_003.factorPrimes(6);
		assertEquals(2, lstP.length);
		assertEquals(2, lstP[0]);
		assertContain(lstP, 3);
	}
	public void testEight() throws Exception{
		int[] lstP = Problem_003.factorPrimes(8);
		assertEquals(3, lstP.length);
		assertContainMany(lstP, 3, 2);
	}
	public void testNine() throws Exception{
		int[] lstP = Problem_003.factorPrimes(9);
		assertEquals(2, lstP.length);
		assertContainMany(lstP, 2, 3);
	}
	public void testSixteen() throws Exception{
		int[] lstP = Problem_003.factorPrimes(16);
		assertEquals(4, lstP.length);
		assertContainMany(lstP, 4, 2);
	}
	public void testMax() throws Exception{	//600851475143/1073741824
		int[] lstP = Problem_003.factorPrimes(600851475143L);
		assertEquals(6857, lstP[lstP.length - 1]);
		//assertContainMany(lstP, 4, 2);
	}
	private void assertContain(int[] factor, int n){
		String error = "assertContains: "+n;
		for(int i=0; i<factor.length; i++)
			if(factor[i]==n)
				return;
		fail(error);
	}
	private void assertContainMany(int[] factor, int cnt, int n){
		String error = "assertContainMany: "+cnt+"/"+n;
		int count = 0;
		for(int i=0; i<factor.length; i++)
			if(n==factor[i])
				count++;
		if(cnt != count)
			fail(error);
	}
}
